package com.gxa.admin.controller;

import com.gxa.admin.pojo.dto.GoodsDto;
import com.gxa.admin.pojo.dto.OrderListDto;
import com.gxa.admin.service.GoodsService;
import com.gxa.admin.service.OrderListService;
import com.gxa.admin.utils.QueryResult;
import com.gxa.core.result.MessageCode;
import com.gxa.core.result.Result;
import com.gxa.core.result.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：lizhijun
 * @Package：{PROJECT_NAME}
 * @name：{DATE} {NAME}
 */
@RestController
@RequestMapping("/admin/Goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @PostMapping( "/showGoods")
    public Result getGoodsList(@RequestBody GoodsDto goodsDto) {
        QueryResult queryResult = this.goodsService.getGoodsList(goodsDto);
        if (queryResult != null) {
            return ResultUtils.buildSuccess(queryResult.getCount(), queryResult.getData());
        }
        return ResultUtils.buildFail(MessageCode.UN_KNOW_EXCEPTION);
    }
    @PostMapping( "/addGoods")
    public Result addGoodsList(@RequestBody GoodsDto goodsDto) {
        int i = this.goodsService.addGoodsList(goodsDto);
        if (i!=1) {
            return ResultUtils.buildFail(MessageCode.UN_KNOW_EXCEPTION);
        }
        return ResultUtils.buildSuccess();
    }
    @PostMapping( "/update")
    public Result updateGoods(@RequestBody GoodsDto goodsDto) {
        this.goodsService.updateGoods(goodsDto);
//        if (i!=1) {
//            return ResultUtils.buildFail(MessageCode.UN_KNOW_EXCEPTION);
//        }
        return ResultUtils.buildSuccess();
    }
    @GetMapping( "/deleteGoods")
    public Result deleteGoods(GoodsDto goodsDto) {
        int result = this.goodsService.deleteGoods(goodsDto);
        System.out.println("+++++++删除接口+++++++++++++");
        System.out.println("传过来的数据"+goodsDto);
        if (result!=1) {
            return ResultUtils.buildFail(MessageCode.UN_KNOW_EXCEPTION);
        }
        return ResultUtils.buildSuccess();
    }

}
